Component({
  properties: {
    todoList: {
      type: Array,
      value: []
    },
  },

  data: {
    inputText: '',
  },

  methods: {
    changeInput(event) {
      this.setData({inputText: event.detail.value})
    },

    addTodo(event) {
      const {inputText} = this.data
      const {todoList} = this.properties
      const {uuid} = require('../../../utils/util')
      
      if (inputText.trim() === '' || inputText === undefined || inputText === null) {
        wx.showToast({
          title: '任务内容不能为空',
          icon: 'none'
        })

        return
      }
      
      const todo = {
        id: uuid(),
        text: inputText,
        done: false,
      }

      this.setData({inputText: ''})
      this.triggerEvent('updateData', {todoList: [todo, ...todoList]})
    },
  }
})